import java.util.ArrayList;
import java.util.List;

/**
 * This abstract Ship models the characteristics of a ship piece within the
 * battleship game. Each ship instance will have a name and corresponding
 * length. A ship will be considered sunk if all cells it occupies are hit.
 * 
 * @mathmodel Each ship has a unique name and a non-negative integer length.
 * @constraint The ship's length must be one of the set {2,3,4,5}.
 * @mathdef The ship is a sequence of cell locations.
 * @initially Constructor (String name, int length)
 * @author Vo, Wu, and Wyan
 * */

public abstract class Ship {
	/**
	 * The name of the specific type of the ship.
	 */
	private String name;

	/**
	 * The length of specific type of the ship.
	 */
	private int length;

	/**
	 * The number of hits that this ship has endured.
	 */
	private int hitCount;

	/**
	 * The location of the cells that this ship occupies.
	 */
	private List<String> cells;

	/**
	 * Two argument constructor that produces a ship with a name and length.
	 * 
	 * @param name
	 *            Name of the ship.
	 * @param length
	 *            The length of the ship.
	 * @requires For each pair of <String,int> there is a complimentary
	 *           battleship game piece it models.
	 * @ensures The ship has not been hit and occupies no cells upon
	 *          initialization.
	 */
	public Ship(String name, int length) {
		this.name = name;
		this.length = length;
		this.hitCount = 0;
		this.cells = new ArrayList<String>();
	}

	/**
	 * @return The name of the ship.
	 */
	public final String getName() {
		return this.name;
	}

	/**
	 * @return The length of the ship.
	 */
	public final int getLength() {
		return this.length;
	}

	/**
	 * @return The hit count of the ship
	 */
	public final int getHitCount() {
		return this.hitCount;
	}

	/**
	 * @return The locations of the cells this ship occupies.
	 */
	public final List<String> getCells() {
		return this.cells;
	}

	/**
	 * Increase the amount of hits this ship has endured by one.
	 * 
	 * @alters hitCount
	 * @ensures hitCount = #hitCount + 1
	 */
	public final void hit() {
		hitCount++;
	}

	/**
	 * Determines whether or not the ship is still in play or not.
	 * 
	 * @return true if this ship has been sunk or false otherwise
	 */
	public final Boolean isSunk() {
		return (this.hitCount == this.length);
	}

	/**
	 * Adds a single cell space into the array of cells the ship occupies.
	 * 
	 * @param cell
	 *            The cell to be added to the ship's occupation.
	 */
	public final void addCell(String cell) {
		this.cells.add(cell);
	}

}
